package com.primal.mvc;

import com.alibaba.fastjson2.writer.ObjectWriterImplMap;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author:whh
 * @date: 2024-01-18 21:53
 * <p></p>
 */
@Configuration
@EnableWebMvc
public class WebMvcConfig {

    /**
     * 作用类似与<mvc:annotation-driven></mvc:annotation-driven>
     *
     * DispatcherServlet#initStrategies方法初始化时会加载该 HandlerAdapter
     * @return
     */
    @Bean
    public RequestMappingHandlerAdapter requestMappingHandlerAdapter(){
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        RequestMappingHandlerAdapter mappingHandlerAdapter = new RequestMappingHandlerAdapter();
        mappingHandlerAdapter.setMessageConverters(Collections.singletonList(converter));
        return mappingHandlerAdapter;
    }

}
